//
//  LTFEightTableViewCell.m
//  NeteaseNews
//
//  Created by liutaifeng on 16/4/27.
//  Copyright © 2016年 liutaifeng. All rights reserved.
//

#import "LTFEightTableViewCell.h"
#import "AFNetworking.h"
#import "UIImageView+AFNetworking.h"
#import "IsNight.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface LTFEightTableViewCell ()
@property (nonatomic, retain) UIView *backView;
@property (nonatomic, retain) UIImageView *picImageView;
@property (nonatomic, retain) UILabel *contentLabel;
@property (nonatomic, retain) UIView *line;
@property (nonatomic, retain) UIButton *upButton;
@property (nonatomic, retain) UILabel *upLabel;
@property (nonatomic, retain) UIButton *downButton;
@property (nonatomic, retain) UILabel *downLabel;
@property (nonatomic, retain) UIButton *replyButton;
@property (nonatomic, retain) UILabel *replyLabel;
@property (nonatomic, retain) UIButton *shareButton;
@end

@implementation LTFEightTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView {
    self.model = [[[LTFJokeModel alloc] init] autorelease];
    //背景
    self.backView = [[UIView alloc] init];
    [self.contentView addSubview:_backView];
    //_backView.backgroundColor = [UIColor blueColor];
    [_backView release];
    //图片
    self.picImageView = [[UIImageView alloc] init];
    [_backView addSubview:_picImageView];
    [_picImageView release];
    
    //内容
    self.contentLabel = [[UILabel alloc] init];
    [_backView addSubview:_contentLabel];
    //_contentLabel.backgroundColor = [UIColor blueColor];
    [_contentLabel release];
    //分割线
    self.line = [[UIView alloc] init];
    [_backView addSubview:_line];
    _line.backgroundColor = [UIColor lightGrayColor];
    [_line release];
    //支持按钮
    self.upButton = [UIButton buttonWithType:UIButtonTypeSystem];
    //_upButton.backgroundColor = [UIColor blackColor];
    [_backView addSubview:_upButton];
    //支持数
    self.upLabel = [[UILabel alloc] init];
    [_backView addSubview:_upLabel];
    [_upLabel release];
    
    //不支持按钮
    self.downButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_backView addSubview:_downButton];
    //不支持数
    self.downLabel = [[UILabel alloc] init];
    [_backView addSubview:_downLabel];
    [_downLabel release];
    
    //回复按钮
    self.replyButton = [UIButton buttonWithType:UIButtonTypeSystem];
    //_replyButton.backgroundColor = [UIColor redColor];
    [_backView addSubview:_replyButton];
    //回复数
    self.replyLabel = [[UILabel alloc] init];
    [_backView addSubview:_replyLabel];
    //分享按钮
    self.shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
    //_shareButton.backgroundColor = [UIColor whiteColor];
    [_backView addSubview:_shareButton];
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if ([IsNight nowIsNight]) {
        self.contentView.backgroundColor = [IsNight nightColor];
        _contentLabel.textColor = [IsNight textNightColor];
        _line.backgroundColor = [UIColor whiteColor];
        _upLabel.textColor = [IsNight textNightColor];
        _downLabel.textColor = [IsNight textNightColor];
        _replyLabel.textColor = [IsNight textNightColor];
        _backView.backgroundColor = [IsNight nightColor];
    }
    else {
        self.contentView.backgroundColor = [UIColor whiteColor];
        _contentLabel.textColor = [UIColor blackColor];
        _line.backgroundColor = [UIColor blackColor];
        _upLabel.textColor = [UIColor blackColor];
        _downLabel.textColor = [UIColor blackColor];
        _replyLabel.textColor = [UIColor blackColor];
        _backView.backgroundColor = [UIColor whiteColor];
    }

    [_picImageView setImageWithURL:[NSURL URLWithString:self.model.imgsrc] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    NSArray *array = [self.model.pixel componentsSeparatedByString:@"*"];
    CGFloat h = (WIDTH - 20) * [array[1] floatValue] / [array[0] floatValue];
    _picImageView.frame = CGRectMake(10, 10, WIDTH - 30, h);
    //内容
    _contentLabel.frame = CGRectMake(10, h + 20, WIDTH - 20, WIDTH);
    _contentLabel.text = _model.digest;
    _contentLabel.numberOfLines = 0;
    [_contentLabel sizeToFit];
    //分割线
    _line.frame = CGRectMake(3, _contentLabel.frame.size.height + 40 + h, WIDTH - 10, 1);
    //支持按钮
    _upButton.frame = CGRectMake(3, _contentLabel.frame.size.height + 50 + h, 30, 30);
    [_upButton setImage:[UIImage imageNamed:@"dian.png"] forState:UIControlStateNormal];
    //支持数
    _upLabel.frame = CGRectMake(33, _contentLabel.frame.size.height + 50 + h, 40, 30);
    _upLabel.text = [NSString stringWithFormat:@"%d", [_model.upTimes intValue]];
    //不支持按钮
    _downButton.frame = CGRectMake(85, _contentLabel.frame.size.height + 50 + h, 30, 30);
    [_downButton setImage:[UIImage imageNamed:@"buzan.png"] forState:UIControlStateNormal];
    //不支持数
    _downLabel.frame = CGRectMake(115, _contentLabel.frame.size.height + 50 + h, 40, 30);
    _downLabel.text = [NSString stringWithFormat:@"%d", [_model.downTimes intValue]];
    //回复按钮
    _replyButton.frame = CGRectMake(260, _contentLabel.frame.size.height + 50 + h, 30, 30);
    [_replyButton setImage:[UIImage imageNamed:@"pinglun.png"] forState:UIControlStateNormal];
    //回复数
    _replyLabel.frame = CGRectMake(290, _contentLabel.frame.size.height + 50 + h, 40, 30);
    _replyLabel.text = [NSString stringWithFormat:@"%d", [_model.replyCount intValue]];
    //分享按钮
    _shareButton.frame = CGRectMake(320, _contentLabel.frame.size.height + 50 + h, 30, 30);
    [_shareButton setImage:[UIImage imageNamed:@"分享.png"] forState:UIControlStateNormal];
    //背景
    _backView.frame = CGRectMake(5, 5, WIDTH - 10, _contentLabel.frame.size.height + 80 + h);
    _backView.layer.borderWidth = 1;
    _backView.layer.cornerRadius = 5;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
